package com.challenge.Order;

import com.challenge.Constants.IConstants;

public class Order {
    String name;
    String temp;
    double shelfLife;
    double decayRate;
    double orderAge;
    String shelfType;
    int leftLifeTime;

    public int getLeftLifeTime() {
        return leftLifeTime;
    }

    public void setLeftLifeTime(int leftLifeTime) {
        this.leftLifeTime = leftLifeTime;
    }

    public String getShelfType() {
        return shelfType;
    }

    public void setShelfType(String shelfType) {
        this.shelfType = shelfType;
    }
    public void setDecayRate(double decayRate) {
        this.decayRate = decayRate;
    }

    public double getOrderAge() {
        return orderAge;
    }

    public void setOrderAge(double orderAge) {
        this.orderAge = orderAge;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTemp() {
        return temp;
    }

    public void setTemp(String temp) {
        this.temp = temp;
    }

    public double getShelfLife() {
        return shelfLife;
    }

    public void setShelfLife(double shelfLife) {
        this.shelfLife = shelfLife;
    }

    public double getDecayRate() {
        return decayRate;
    }


    //计算每个订单经过多少秒会过期
    public int orderValueCompute() {
        double value = shelfLife;//设置一个初始值
        int order_age = 0;

        while(value>0){
            if(this.getShelfType().equals(IConstants.OVERFLOW)){
                order_age++;
                value = (shelfLife - order_age) - ( decayRate * 2 * order_age);
            }else{
                order_age++;
                value = (shelfLife - order_age) - ( decayRate * order_age);

            }
        }

        return order_age;

    }
}
